package thread;

class MyThread extends Thread{
    //在此类中重写run方法
    @Override
    public void run() {
        while (true) {
            System.out.println("hello world");
            //睡一会儿
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}

public class ThreadDemo1 {

    public static void main(String[] args) {
        Thread thread = new MyThread();
        thread.start();//线程中的特殊方法 - 创建一个线程
        while (true) {
            System.out.println("hello java");
            //睡一会儿
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
